package com.musifind.adapters;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.musifind.activities.R;
import com.musifind.models.LiveUserItems;

public class LiveUserListAdapter extends ArrayAdapter<LiveUserItems> {

	Context context;
	int layoutResourceId;
	ArrayList<LiveUserItems> objects = new ArrayList<LiveUserItems>();
	LiveUserItems matchItems;

	public LiveUserListAdapter(Context context, int layoutResourceId, ArrayList<LiveUserItems> objects) {
		super(context, layoutResourceId, objects);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.objects = objects;
	}

	public static class LiveUsersHolder {
		ImageView imgUser;
		TextView txtUserName;
		TextView txtTrackName;
		TextView txtArtistName;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		View row = convertView;

		LiveUsersHolder holder;

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new LiveUsersHolder();
			holder.imgUser = (ImageView) row.findViewById(R.id.imgLiveUsersListUser);
			holder.txtUserName = (TextView) row.findViewById(R.id.txtLiveUsersListUser);
			holder.txtTrackName = (TextView) row.findViewById(R.id.txtLiveUsersListTrackName);
			holder.txtArtistName = (TextView) row.findViewById(R.id.txtLiveUsersListArtistName);
			row.setTag(holder);
		}

		holder = (LiveUsersHolder) row.getTag();

		final LiveUserItems mItems = objects.get(position);

		holder.imgUser.setImageBitmap(mItems.getUserImage());
		// holder.imgUser.setImageBitmap(GeneralHelper.roundCornerImage((Bitmap) GlobalCache.getValueByKey("userPicture"),
		// 95));
		holder.txtUserName.setText(mItems.getUserName());
		holder.txtTrackName.setText(mItems.getTrackName());
		holder.txtArtistName.setText(mItems.getArtistName());
		return row;

	}

	@Override
	public int getItemViewType(int position) {
		return position;
	}

	@Override
	public int getViewTypeCount() {
		return 500;
	}
}
